home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C21 / Transform.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  692 b   |  28 lines

  1. //: C21:Transform.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Use of STL transform() algorithm
  7. #include "Counted.h"
  8. #include <iostream>
  9. #include <vector>
  10. #include <algorithm>
  11. using namespace std;
  12.  
  13. template<class T>
  14. T* deleteP(T* x) { delete x; return 0; }
  15.  
  16. template<class T> struct Deleter {
  17.   T* operator()(T* x) { delete x; return 0; }
  18. };
  19.  
  20. int main() {
  21.   CountedVector cv("one");
  22.   transform(cv.begin(), cv.end(), cv.begin(), 
  23.     deleteP<Counted>);
  24.   CountedVector cv2("two");
  25.   transform(cv2.begin(), cv2.end(), cv2.begin(),
  26.     Deleter<Counted>());
  27. } ///:~
  28.